const express = require('express');
const fs = require('fs');
const path = require('path');

let app = express();

// 声明中间件函数
let recordMiddleware = (req,res,next)=>{
    let {url,ip} = req;
    fs.appendFileSync(path.resolve(__dirname,'./access.log'), `${url} ${ip}\r\n`);
    next()
}

// 注册全局中间件
app.use(recordMiddleware)

// 路由
app.get('/login',(req,res)=>{
    res.send('登录页')
})
app.get('/reg',(req,res)=>{
    res.send('注册页')
})

app.all('*', (req,res)=>{
    res.send('404 NOT FOUND')
})

app.listen(9527,()=>{
    console.log('启动成功....');
})